//package com.hl.framework.permission.config;
//
//import cn.hutool.extra.spring.SpringUtil;
//import com.hl.framework.core.security.LoginUser;
//import com.hl.framework.permission.core.rule.dept.DeptDataPermissionRule;
//import com.hl.framework.permission.core.rule.dept.DeptDataPermissionRuleCustomizer;
//import org.springframework.boot.autoconfigure.AutoConfiguration;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.context.annotation.Bean;
//
//import java.util.List;
//
///**
// * 基于部门的数据权限 AutoConfiguration
// *
// * @author 芋道源码
// */
//@AutoConfiguration
//@ConditionalOnClass(LoginUser.class)
//@ConditionalOnBean(value = {DeptDataPermissionRuleCustomizer.class})
//public class HandlinkDeptDataPermissionAutoConfiguration {
//
//    @Bean
//    public DeptDataPermissionRule deptDataPermissionRule(PermissionCommonApi permissionApi,
//                                                         List<DeptDataPermissionRuleCustomizer> customizers) {
//        // Cloud 专属逻辑：优先使用本地的 PermissionApi 实现类，而不是 Feign 调用
//        // 原因：在创建租户时，租户还没创建好，导致 Feign 调用获取数据权限时，报“租户不存在”的错误
//        try {
//            PermissionCommonApi permissionApiImpl = SpringUtil.getBean("permissionApiImpl", PermissionCommonApi.class);
//            if (permissionApiImpl != null) {
//                permissionApi = permissionApiImpl;
//            }
//        } catch (Exception ignored) {}
//
//        // 创建 DeptDataPermissionRule 对象
//        DeptDataPermissionRule rule = new DeptDataPermissionRule(permissionApi);
//        // 补全表配置
//        customizers.forEach(customizer -> customizer.customize(rule));
//        return rule;
//    }
//
//}
